import type { BingElements } from '../../../../../../../../types/constants/personalization/bing'
import { ThemeVarService } from '../../../../../../../../lib/abstract/style/theme_var/service'
import { PAGE_ELEMENTS, SUPPORTED_PLATFORMS } from '../../../../../../../../types/constants'
import { SearchCommonStyles } from '../../common'

export class BingDictionaryPage {
  elements: BingElements = PAGE_ELEMENTS[SUPPORTED_PLATFORMS.BING]
  private static instance: BingDictionaryPage
  private readonly themeVarService: ThemeVarService = ThemeVarService.getInstance()
  private readonly searchCommonStyles: SearchCommonStyles = SearchCommonStyles.getInstance()

  /**
   * 获取单例实例
   */
  public static getInstance(): BingDictionaryPage {
    if (!BingDictionaryPage.instance) {
      BingDictionaryPage.instance = new BingDictionaryPage()
    }
    return BingDictionaryPage.instance
  }

  init(): void {
  }

  /**
   * 无搜索结果样式
   */
  noSearchResult(): string {
    return ``
  }

  getMainStyles(): string {
    return `
    .contentPadding {
      display: flex !important;
      justify-content: center !important;
      padding-left: 0 !important;
      
      &:has(.no_results) {
        width: 100% !important;
        max-width: 100% !important;

        /* 无搜索结果 */
        .no_results {
          div:not([class]) {
            color: var(${this.themeVarService.search.resultItem.noItemTip}) !important;
          }
        }
        
        .dymp_sm_top {
          .dymp_link {
            a {
              color: var(${this.themeVarService.link.default.text}) !important;
              
              &:hover {
                text-decoration: none !important;
                color: var(${this.themeVarService.link.default.textHover}) !important;
              }
            }
          }
        }
      }
      
      .lf_area {
        width: 100% !important;

        .qdef {
          .hd_area {
            #headword {
              h1 {
                strong {
                  color: var(${this.themeVarService.search.default.text}) !important;
                }
              }
            }
          }
          
          ul {
            li {
              .def {
                a {
                  color: var(${this.themeVarService.search.default.text}) !important;
                }
              }
            }
          }
          
          .df_div {
            .tb_div {
              border-bottom: none !important;
            
              h2 {
                color: var(${this.themeVarService.search.default.text}) !important;
              }
            }
            
            .se_d.b_primtxt {
              color: var(${this.themeVarService.search.default.text}) !important;
            }
            
            .df_cr_w {
              a, span {
                color: var(${this.themeVarService.search.default.text}) !important;
              }
            }
            
            #defid {
              table {
                td {
                  div {
                    color: var(${this.themeVarService.search.default.text}) !important;
                  }
                  
                  .sen_li {
                    a {
                      color: var(${this.themeVarService.link.default.text}) !important;
                    }
                  }
                }
              }
              
              #df_wbi {
                #id_clsp_web_More, #id_clsp_web_less {
                  color: var(${this.themeVarService.link.default.text}) !important;
                }
              }
            }
          }
        }

        .se_div {
          .tb_div {
            border-bottom: none !important;
          
            h2 {
              color: var(${this.themeVarService.search.default.text}) !important;
            }
          }
          
          #sentenceCon {
            #filter {
              .tbs_b.b_primtxt {
                color: var(${this.themeVarService.search.default.text}) !important;
              }
              
              .senDef, #confil, #src, #diff {
                span {
                  &.filtext {
                    color: var(${this.themeVarService.message.success.textPrimary}) !important;
                  }
                  
                  &.sensep {
                    margin-right: 5px !important;
                    opacity: 0 !important;
                  }
                }

                #sde_all_te, #sc_all_te, #ss_all_te, #sd_all_te {
                  color: var(${this.themeVarService.message.success.textPrimary}) !important;
                  
                  &[style*="display: none"] {
                    color: var(${this.themeVarService.search.default.text}) !important;
                  }
                }
                
                a {
                  color: var(${this.themeVarService.link.default.text}) !important;
                  
                  &:hover {
                    color: var(${this.themeVarService.link.default.textHover}) !important;
                    text-decoration: none !important;
                  }
                }
              }
            }
            
            #filshow #morefilter, #filhide #hidefilter {
              color: var(${this.themeVarService.link.default.text}) !important;
            }
            
            #loaddataid {
              left: 50% !important;
              transform: translateX(-50%) !important;
            }
            
            #sentenceSeg {
              ${this.searchCommonStyles.resultContainerStyles()}
              
              /* 无搜索结果 */
              > div:has(> span) {
                display: flex !important;
                align-items: center !important;
                justify-content: center !important;
                
                span {
                  color: var(${this.themeVarService.search.resultItem.noItemTip}) !important;
                }
              }

              /* 有搜索结果 */
              > .se_li {
                ${this.searchCommonStyles.resultItemStyles()}
                display: inline-flex !important;
                
                a, span {
                  color: var(${this.themeVarService.search.default.text}) !important;
                  
                  &.b_dictHighlight {
                    color: var(${this.themeVarService.em.text}) !important;
                  }
                }
                
                .mm_div {
                  position: absolute !important;
                  right: 16px !important;
                  bottom: 0 !important;
                }
              }
            }
          }
        }
      }
    }
    `
  }
}
